package com.tpp.scheduler.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tpp.comm.pojo.TpScheduler;
import com.tpp.scheduler.mapper.SchedulerMapper;
import com.tpp.scheduler.service.SchedulerService;
import com.tpp.scheduler.vo.SchedulerVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SchedulerServiceImpl implements SchedulerService {

    @Resource
    private SchedulerMapper schedulerMapper;

    @Override
    public List<SchedulerVo> queryItemScheduler(Integer itemId) {
        LambdaQueryWrapper<TpScheduler> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(TpScheduler::getItemId,itemId);
        wrapper.orderByDesc(TpScheduler::getStartTime);
        List<TpScheduler> tpSchedulers = schedulerMapper.selectList(wrapper);
        return tpSchedulers.stream().map(tpScheduler -> {
            SchedulerVo vo = new SchedulerVo();
            BeanUtils.copyProperties(tpScheduler,vo);
            return vo;
        }).toList();
    }
}
